home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 124 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  39 lines

  1. Newsgroups: comp.std.c
  2. Path: howland.reston.ans.net!torn!sq!msb
  3. From: msb@sq.com (Mark Brader)
  4. Subject: Re: atexit() and return from main()
  5. Message-ID: <1996Jan17.105929.7146@sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de>
  8. Date: Wed, 17 Jan 1996 10:59:29 GMT
  9.  
  10. Thomas.Koenig@ciw.uni-karlsruhe.de writes:
  11. /* code compressed and excerpted --msb */
  12. > char *a;
  13. > void printit()
  14. > { printf("%s",a); }
  15. > int main()
  16. > { char buffer[]="Hello\n"; a = buffer; atexit(printit); return 0; }
  17. > 6.1.2.4 tells me it isn't, but 5.1.2.2.3 tells me that a return from the
  18. > initial call to main() is equivalent to an exit(), and I don't see a problem
  19. > when I replace the 'return 0' above with an 'exit(0)'.
  20.  
  21. I think that a strict reading of the existing standard requires 5.1.2.2.3
  22. to take precedence (it gives the return special semantics, so it doesn't
  23. really cause the block containing it to be exited from), thus making the
  24. code legal.  However, clearly this was not intended and would be burdensome
  25. to implementers, and I'd expect the code to fail in real life; and it's
  26. probably possible to read it the other way anyway.
  27.  
  28. Defect Report 85 raised this issue and suggested resolving it by explicitly
  29. giving 6.1.2.4 precedence, so that the code would cause undefined behavior.
  30. According to the item posted recently about Technical Corrigendum 2, this
  31. change was accepted and will be officially published soon.
  32. -- 
  33. Mark Brader              "Should array indices start at 0 or 1?  My ecumenical
  34. msb@sq.com                 compromise of 0.5 was rejected without, I thought,
  35. SoftQuad Inc., Toronto      proper consideration."     -- Stan Kelly-Bootle
  36.  
  37. My text in this article is in the public domain.
  38.